package com.czy.mapper;

import com.czy.pojo.Student;
import com.czy.pojo.StudentPage;
import org.apache.ibatis.annotations.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Mapper
public interface StudentMapper {


    /**
     * 条件分页查询学员信息
     */
    public List<Student> list(StudentPage page);

    /**
     * 新增学员信息
     */
    @Insert("insert into student(name, no, gender, phone, id_card, is_college, address, degree, graduation_date, clazz_id, create_time, update_time) " +
            "VALUES(#{name},#{no},#{gender},#{phone},#{idCard},#{isCollege},#{address},#{degree}," +
            "#{graduationDate},#{clazzId},#{createTime},#{updateTime}) ")
    public void insert(Student student);

    /**
     * 根据ID查询学员信息
     */
    @Select("select id, name, no, gender, phone, id_card, is_college, address, degree, graduation_date, clazz_id, violation_count, violation_score, create_time, update_time from student " +
            "where id = #{id}")
    public Student findById(Integer id);

    /**
     * 修改学员信息
     */

    public void update(Student student);

    /**
     * 批量删除学员信息
     */
    public void delete(ArrayList<Integer> ids);

    /**
     * 根据ID查询学员的违纪次数和分数
     */
    @Select("select violation_count,violation_score from student where id = #{id}")
    public Student selectViolation(Integer id);

    /**
     * 添加违纪处理
     */
    @Update("update student set violation_count = #{violationCount}, " +
            "violation_score = #{violationScore} , update_time =#{updateTime} " +
            "where id = #{id}")
    public void updateViolation(Student student);

    /**
     * 统计学员学历人数
     */
    @MapKey("name")
    public List<Map<String, Object>> countDegreeData();

    @MapKey("clazzId")
    public List<Map<String, Object>> getStudentCountData();
}
